// pages/student/mine/mine.js
import {
    ajaxPost,
    showToast
}
from '../../../utils/util'
let app = getApp()

Page({

    /**
     * 页面的初始数据
     */
    data: {
        userSource: {},
        footerSource: [{
                title: '选选',
                url: '/pages/student/list/list',
                img: '/images/icon_footer_icon1.png',
                imgSet: '/images/icon_footer_icon1_set.png',
                select: false
            },
            {
                title: '招聘会',
                url: '/pages/student/home/home',
                img: '/images/icon_footer_icon2.png',
                imgSet: '/images/icon_footer_icon2_set.png',
                select: false
            },
            {
                title: '我的',
                url: '',
                img: '/images/icon_footer_icon3.png',
                imgSet: '/images/icon_footer_icon3_set.png',
                select: true
            },
        ],
    },

    click() {
        let data = {
            token: wx.getStorageSync("token"),
            usertype: 4,
        }
        ajaxPost("/authuser/usertype", data, function (res) {
            if (res.code == 0) {
                if (res.data.is_set_userinfo == 0) {
                    wx.redirectTo({
                        url: "/pages/enterprise/binding/binding"
                    });
                    return;
                }
                wx.redirectTo({
                    url: "/pages/enterprise/home/home"
                });
            } else {
                showToast('text', res.msg);
            }
        });
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        let data = {
            token: wx.getStorageSync("token"),
        }
        ajaxPost("/authuser/myInfo", data, (res) => {
            if (res.code == 0) {
                this.setData({
                    userSource: res.data.user_info
                })
            } else {
                showToast('text', res.msg);
            }
        });

    },
    pusResume() {
        let _this = this
        wx.chooseImage({
            count: 1,
            sizeType: ['compressed'],
            sourceType: ['album', 'camera'],
            success(res) {
                let file = res.tempFilePaths[0]
                wx.showLoading({
                    title: '图片上传中',
                })
                wx.uploadFile({
                    url: app.globalData.ajaxUrl + '/upload/index',
                    filePath: file,
                    name: "file",
                    formData: {
                        token: wx.getStorageSync('token')
                    },
                    success: function (e) {
                        let fileData = JSON.parse(e.data)
                        let newFile = fileData.data
                        let data = {
                            image: newFile,
                        }
                        _this.pustData(data)
                    },
                    fail: function (e) {
                        showToast('error', '上传失败，请重试')
                    },
                    complete: function () {}
                });
            },

        })
    },
    /**
     *  修改个人信息
     * @param {*} data  修改参数
     */
    pustData(data) {
        data.token = wx.getStorageSync('token');
        let _this = this
        ajaxPost("/authuser/setResume", data, (res) => {
            if (res.code == 0) {
                this.onShow()
                wx.hideLoading();
                showToast('success', '修改成功');
            } else {
                showToast('text', res.msg);
            }
        });

    },
})